package br.inatel.wiiproject.view;
import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;

import br.inatel.wiiproject.data.StoredData;


public class RemotePanel extends JPanel {

	private static final long serialVersionUID = 1L;

	private int t = 0;
    private int x = 0;
    private int y = 0;
    
    private int lastX = 0;
    private int lastY = 0;
    private int width = 400;
    private int height = 300;
    boolean isFirstExecution = true;
    private int id = 0;
	
	public RemotePanel(int id) {
		super();
		this.id = id;
		CompoundBorder cb = new CompoundBorder(new TitledBorder(""),new EmptyBorder(20, 20, 20, 20));
		setBorder(cb);
		setSize(width, height);	
		setBackground(Color.GREEN);
		setVisible(true);
	}
	
	public int getID(){
		return this.id;
	}
	
	public void paintComponent(Graphics graphics)
    {

		if (t == 0 /*|| accelerometerSource != lastSource*/)
        {
            graphics.clearRect(0, 0, width, height);
            graphics.fillRect(0, 0, width, height);
            graphics.setColor(Color.WHITE);
            graphics.drawLine(0, height/2, width, height/2);
        }
        
        graphics.setColor(Color.RED);
        graphics.drawLine(t, lastX, t, x);
        graphics.setColor(Color.GREEN);
        graphics.drawLine(t, lastY, t, y);
    }
	
    public void setXY(int x, int y){
    	this.lastX = this.x;
    	this.lastY = this.y;
    	this.x = x;
    	this.y = y;
    	
    }
    
    
   
	public void increaseT() {
//		if(isFirstExecution){
//			this.t = 300;
//			isFirstExecution = false;
//		}
		if (t < width){
			this.t++;			
		}
		else{
			this.t = 0;
			StoredData.saveAll();
		}
		
	}
    
    
}
